<!--
  - Copyright 2011 Angel Sanadinov
  -
  - This file is part of VBox WMI.
  -
  - VBox WMI is free software: you can redistribute it and/or modify
  - it under the terms of the GNU General Public License as published by
  - the Free Software Foundation, either version 3 of the License, or
  - (at your option) any later version.
  -
  - VBox WMI is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU General Public License for more details.
  -
  - You should have received a copy of the GNU General Public License
  - along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
  -->

<%@tag import="java.util.ArrayList"%>
<%@tag import="java.util.HashMap"%>
<%@tag import="Beans.Responses.DataRetrievalComponents.GuestOSTypeDataComponent"%>
<%@tag import="Beans.Responses.DataRetrievalComponents.MiscDataComponent"%>
<%@tag import="Beans.Responses.DataRetrievalResponse"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="jstlc"%>
<%@tag description="Returns the supplied Guest OS Types as <option> tags, separated in <optgroup>s."
       pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>

<%-- Attributes --%>
<%@attribute name="osTypesData" required="true" description="Guest OS types data object."
             rtexprvalue="true" type="DataRetrievalResponse<MiscDataComponent>" %>
<%-- End of Attributes --%>

<%-- Content --%>
<%
    if(osTypesData != null && osTypesData.getRequestResult())
    {
        HashMap<String, ArrayList<GuestOSTypeDataComponent>> osTypesMap = new HashMap<String, ArrayList<GuestOSTypeDataComponent>>();

        for(GuestOSTypeDataComponent osType : osTypesData.getResource().getGuestOSTypes())
        {
            if(osTypesMap.containsKey(osType.getFamilyDescription()))
                osTypesMap.get(osType.getFamilyDescription()).add(osType);
            else
            {
                ArrayList<GuestOSTypeDataComponent> newList = new ArrayList<GuestOSTypeDataComponent>();
                newList.add(osType);
                osTypesMap.put(osType.getFamilyDescription(), newList);
            }
        }

        for(String osTypeKey : osTypesMap.keySet())
        {
            out.print("<optgroup label=\"" + osTypeKey + "\">");
            for(GuestOSTypeDataComponent currentOSType : osTypesMap.get(osTypeKey))
            {
                out.println("<option value=\"" + currentOSType.getOsTypeId() + "\">"
                            + currentOSType.getOsTypeDescription() + "</option>");
            }
            out.print("</optgroup>");
        }
    }
    else
        out.print("<option value=\"0\">N/A</option>");
%>
<%-- End of Content --%>